package leetcode;


/**
 * @author niann
 * @description TODO https://leetcode.cn/problems/valid-palindrome-ii/description/
 * @since 2024/11/13 17:20
 **/
public class LeetCode680 {
    class Solution {
        public boolean validPalindrome(String s) {
            if (s == null || s.isEmpty()) return false;
            if (s.length()==1) return true;
            var i=0;
            var j=s.length()-1;
            while (i<j){
                if (s.charAt(i)!=s.charAt(j)){
                    StringBuilder newS = new StringBuilder(s);
                    newS.deleteCharAt(j);
                    var s2 = newS.toString();
                   if (newS.reverse().toString().contentEquals(s2)){
                       return true;
                   }else {
                       StringBuilder new2 = new StringBuilder(s);
                       new2.deleteCharAt(i);
                       var s3 =new2.toString();
                       return new2.reverse().toString().contentEquals(s3);
                   }
                }else {
                    i++;j--;
                }
            }
            return true;
        }
    }

    public static void main(String[] args) {
//        Solution solution = new LeetCode680().new Solution();
//        System.out.println(solution.validPalindrome("abc"));
    }

}
